<?php
/**
 * @file newsinfo.php
 * @author LinLin
 * @date 2017年1月17日 下午6:36:32
 * @brief 
 */

namespace haibao\cms\business;

use \haibao\cms\data\NewsInfo as NewsInfoData;
use haibao\frame\data\query\Condition;

class NewsInfo extends \haibao\cms\business\Base {
    
    public static function getAllList($filter){
        $data = new NewsInfoData();
        return $data->getAllList($filter);
    }
    
    public static function getOneNewsById($id){
        $data = new NewsInfoData();
        return $data->getOneNewsById($id);
    }
    
    public static function saveNewsInfo($model){
        if(!$model->Title){
            throw new BusinessException('文章标题不能为空');
        }
        if(!$model->Content){
            throw new BusinessException('文章内容不能为空');
        }
        if(!$model->Id){
            $model->CreateBy = self::getCurrentUser()->Id;
            $model->CreateTime  = new \DateTime();
        }else{
            $newsInfo = self::getOneNewsById($model->Id);
            $model->CreateBy = $newsInfo->CreateBy;
            $model->CreateTime = $newsInfo->CreateTime;
        }
        
        $data = new NewsInfoData();
        return $data->saveNewsInfo($model);
    }
}